import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import { defineConfig } from 'vite'

// const target = 'http://47.104.227.180:7001/api'
const target = 'http://localhost:7001/'
// const target = 'https://oj.hterobot.com/api'
// const target = 'https://public.hterobot.com/api'
console.log("process.env.NODE_OPTIONS", process.env.NODE_OPTIONS)
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  base: process.env.NODE_ENV === 'production' ?
    'https://cdn.hterobot.com/noipcode/' : '/',
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src'),
    },
  },
  build: {
    rollupOptions: {
      input: {
        'index': resolve(__dirname, 'public/index.html'),
        'ojSaas': resolve(__dirname, 'public/ojSaas.html'),
        'saasMgmt': resolve(__dirname, 'public/saasMgmt.html'),
        'science': resolve(__dirname, 'public/BeijingScienceConter.html'),
        'sciencechat': resolve(__dirname, 'public/sciencechat.html'),
        'scienceyun': resolve(__dirname, 'public/scienceyun.html'),
        'bjsc': resolve(__dirname, 'public/bjsc.html'),
        'monitor': resolve(__dirname, 'public/monitor.html'),
        'admin': resolve(__dirname, 'public/admin.html'),
        'logs': resolve(__dirname, 'public/logs.html'),
        'h51': resolve(__dirname, 'public/h51.html'),
        'question': resolve(__dirname, 'public/question.html'),
        'huilongguan': resolve(__dirname, 'public/huilongguan.html'),
        'huilongguanoj': resolve(__dirname, 'public/huilongguan-oj.html'),
        'kangbang': resolve(__dirname, 'public/kangbang.html'),
        'tuyaiot': resolve(__dirname, 'public/tuyaiot.html'),
        'tuyaiotv2': resolve(__dirname, 'public/tuyaiotv2.html'),
        'yinchuan': resolve(__dirname, 'public/yinchuan.html'),
        'changping1': resolve(__dirname, 'public/changping1.html'),
        'h5index': resolve(__dirname, 'public/h5index.html'),
        'stc': resolve(__dirname, 'public/stc.html'),
        'stclogin': resolve(__dirname, 'public/stclogin.html'),
        'manage': resolve(__dirname, 'public/manage.html'),
        'qianxuesenzhongxue': resolve(__dirname, 'public/qianxuesenzhongxue.html'),
        'hdbm': resolve(__dirname, 'public/hdbm.html'),
        // 码客行
        'acCoder': resolve(__dirname, 'public/acCoder.html'), // admin管理
        'acCoderOj': resolve(__dirname, 'public/acCoderOj.html'), // OJ
        'acCoderSaas': resolve(__dirname, 'public/acCoderSaas.html'), // saas
        'acCoderSaasMgmt': resolve(__dirname, 'public/acCoderSaasMgmt.html'), // saasMgmt
        'acCoderH5': resolve(__dirname, 'public/acCoderH5.html'), // acCoderH5
        'mathH5': resolve(__dirname, 'public/mathH5.html'), // mathH5
        
        'newh5': resolve(__dirname, 'public/newh5.html'), // mathH5
        'teamchart': resolve(__dirname, 'public/teamchart.html'), // teamchart
        // 新华书店
        'xinhuashudian': resolve(__dirname, 'public/xinhuashudian.html'), // admin管理
        'xinhuashudianOj': resolve(__dirname, 'public/xinhuashudianOj.html'), // OJ
        'xinhuashudianSaas': resolve(__dirname, 'public/xinhuashudianSaas.html'), // saas
        'xinhuashudianSaasMgmt': resolve(__dirname, 'public/xinhuashudianSaasMgmt.html'), // saasMgmt
        'xinhuashudianH5': resolve(__dirname, 'public/xinhuashudianH5.html'), // acCoderH5

      },
    },
    sourcemap: process.env.NODE_ENV === 'production' ? false : 'inline'
  },
  server: {
    host: true,
    port: 4000,
    proxy: {
      "/api": {
        target,
        changeOrigin: true,
        rewrite: (path: string) => path.replace(/^\/api/, '')
      },
      "/socket.io": {
        target,
        changeOrigin: true,
        ws: true
      },
      // "/_AMapService": {
      //   target: 'https://public.hterobot.com/_AMapService',
      //   rewrite: (path: string) => {
      //     console.log(path)
      //     return path.replace(/^\/_AMapService/, '')
      //   }
      // }
      // "/_AMapService/v4/map/styles": {
      //   // target: 'https://webapi.amap.com/v4/map/styles?jscode=053e3724a3c024e46d5d97621a56f111',
      //   rewrite: (path) => {
      //     const n = new URL(path)
      //     n.host = 'webapi.amap.com'
      //     n.searchParams.set('jscode', '053e3724a3c024e46d5d97621a56f111')
      //     return n.href
      //   }
      // },
      // "/_AMapService/v3/vectormap": {
      //   // target: 'https://fmap01.amap.com/v3/vectormap?jscode=053e3724a3c024e46d5d97621a56f111',
      //   rewrite: (path) => {
      //     const n = new URL(path)
      //     n.host = 'fmap01.amap.com'
      //     n.searchParams.set('jscode', '053e3724a3c024e46d5d97621a56f111')
      //     return n.href
      //   }
      // },
      // "/_AMapService/": {
      //   // target: 'https://restapi.amap.com/?jscode=053e3724a3c024e46d5d97621a56f111',
      //   rewrite: (path) => {
      //     const n = new URL(path)
      //     n.host = 'restapi.amap.com'
      //     n.searchParams.set('jscode', '053e3724a3c024e46d5d97621a56f111')
      //     return n.href
      //   }
      // },
    },
  }
})
